home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-admin / theme-editor.php < prev    next >
Encoding:
PHP Script  |  2005-04-20  |  4.0 KB  |  158 lines

  1. <?php
  2. require_once('admin.php');
  3.  
  4. $title = __("Edit Themes");
  5. $parent_file = 'themes.php';
  6.  
  7. $wpvarstoreset = array('action','redirect','profile','error','warning','a','file', 'theme');
  8. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  9.     $wpvar = $wpvarstoreset[$i];
  10.     if (!isset($$wpvar)) {
  11.         if (empty($_POST["$wpvar"])) {
  12.             if (empty($_GET["$wpvar"])) {
  13.                 $$wpvar = '';
  14.             } else {
  15.                 $$wpvar = $_GET["$wpvar"];
  16.             }
  17.         } else {
  18.             $$wpvar = $_POST["$wpvar"];
  19.         }
  20.     }
  21. }
  22.  
  23. $themes = get_themes();
  24.  
  25. if (empty($theme)) {
  26.     $theme = get_current_theme();
  27. } else {
  28.     $theme = stripslashes($theme);
  29.  }
  30.  
  31.  
  32. if ( ! isset($themes[$theme]) )
  33.     die(__('The requested theme does not exist.'));
  34.  
  35. $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
  36.  
  37. if (empty($file)) {
  38.     $file = $allowed_files[0];
  39. }
  40.  
  41. $file = validate_file_to_edit($file, $allowed_files);
  42. $real_file = get_real_file_to_edit($file);
  43.  
  44. switch($action) {
  45.  
  46. case 'update':
  47.  
  48.     if ($user_level < 5) {
  49.         die(__('<p>You have do not have sufficient permissions to edit templates for this blog.</p>'));
  50.     }
  51.  
  52.     $newcontent = stripslashes($_POST['newcontent']);
  53.     $theme = urlencode($theme);
  54.     if (is_writeable($real_file)) {
  55.         $f = fopen($real_file, 'w+');
  56.         fwrite($f, $newcontent);
  57.         fclose($f);
  58.         header("Location: theme-editor.php?file=$file&theme=$theme&a=te");
  59.     } else {
  60.         header("Location: theme-editor.php?file=$file&theme=$theme");
  61.     }
  62.  
  63.     exit();
  64.  
  65. break;
  66.  
  67. default:
  68.     
  69.     require_once('admin-header.php');
  70.     if ($user_level <= 5) {
  71.         die(__('<p>You have do not have sufficient permissions to edit themes for this blog.</p>'));
  72.     }
  73.  
  74.     update_recently_edited($file);
  75.     
  76.     if (!is_file($real_file))
  77.         $error = 1;
  78.     
  79.     if (!$error && filesize($real_file) > 0) {
  80.         $f = fopen($real_file, 'r');
  81.         $content = fread($f, filesize($real_file));
  82.         $content = htmlspecialchars($content);
  83.     }
  84.  
  85.     ?>
  86. <?php if (isset($_GET['a'])) : ?>
  87.  <div class="updated"><p><?php _e('File edited successfully.') ?></p></div>
  88. <?php endif; ?>
  89.  <div class="wrap">
  90.   <form name="theme" action="theme-editor.php" method="post"> 
  91.         <?php _e('Select theme to edit:') ?>
  92.         <select name="theme" id="theme">
  93.     <?php
  94.         foreach ($themes as $a_theme) {
  95.         $theme_name = $a_theme['Name'];
  96.         if ($theme_name == $theme) $selected = " selected='selected'";
  97.         else $selected = '';
  98.         $theme_name = wp_specialchars($theme_name, true);
  99.         echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
  100.     }
  101. ?>
  102.  </select>
  103.  <input type="submit" name="Submit" value="<?php _e('Select') ?> »" />
  104.  </form>
  105.  </div>
  106.  
  107.  <div class="wrap"> 
  108.   <?php
  109.     if (is_writeable($real_file)) {
  110.         echo '<h2>' . sprintf(__('Editing <code>%s</code>'), $file) . '</h2>';
  111.     } else {
  112.         echo '<h2>' . sprintf(__('Browsing <code>%s</code>'), $file) . '</h2>';
  113.     }
  114.     ?>
  115.     <div id="templateside">
  116.   <h3><?php printf(__("<strong>'%s'</strong> theme files"), $theme) ?></h3>
  117.  
  118. <?php
  119. if ($allowed_files) :
  120. ?>
  121.   <ul>
  122. <?php foreach($allowed_files as $allowed_file) : ?>
  123.          <li><a href="theme-editor.php?file=<?php echo "$allowed_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo get_file_description($allowed_file); ?></a></li>
  124. <?php endforeach; ?>
  125.   </ul>
  126. <?php endif; ?>
  127. </div> 
  128.     <?php
  129.     if (!$error) {
  130.     ?> 
  131.   <form name="template" id="template" action="theme-editor.php" method="post">
  132.          <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> 
  133.      <input type="hidden" name="action" value="update" /> 
  134.      <input type="hidden" name="file" value="<?php echo $file ?>" /> 
  135.      <input type="hidden" name="theme" value="<?php echo $theme ?>" />
  136.          </div>
  137. <?php if ( is_writeable($real_file) ) : ?>
  138.      <p class="submit">
  139. <?php
  140.     echo "<input type='submit' name='submit' value='    " . __('Update File') . " »' tabindex='2' />";
  141. ?>
  142. </p>
  143. <?php else : ?>
  144. <p><em><?php _e('If this file was writable you could edit it.'); ?></em></p>
  145. <?php endif; ?>
  146.    </form> 
  147.   <?php
  148.     } else {
  149.         echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
  150.     }
  151.     ?> 
  152. </div> 
  153. <?php
  154. break;
  155. }
  156.  
  157. include("admin-footer.php") ?> 
  158.